package cn.itcast.web.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import cn.itcast.bean.Person;
import cn.itcast.service.PersonService;
import cn.itcast.web.formbean.PersonForm;

public class PersonManageAction extends DispatchAction {

	@Resource PersonService personService;
	/* (non-Javadoc)
	 * @see org.apache.struts.actions.DispatchAction#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	public ActionForward add(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		PersonForm formBean = (PersonForm)form;
		personService.save(new Person(formBean.getName()));
		request.setAttribute("message","添加成功" );
		return mapping.findForward("message");
	}
	
}
